﻿Namespace Othello
    ''' <summary>
    ''' Summary description for Statistics.
    ''' </summary>
    Public Class Statistics
        ' Define the game statistics.
        Public BlackWins As Integer
        Public WhiteWins As Integer
        Public OverallDraws As Integer
        Public BlackTotalScore As Integer
        Public WhiteTotalScore As Integer
        Public ComputerWins As Integer
        Public UserWins As Integer
        Public VsComputerDraws As Integer
        Public ComputerTotalScore As Integer
        Public UserTotalScore As Integer

        '
        ' Creates a new Statistics object will all counts set to zero.
        '
        Public Sub New()
            '
            ' TODO: Add constructor logic here
            '

            ' Initialize the game statistics.
            Me.Reset()
        End Sub

        '
        ' Creates a new Statistics object by copying and existing one.
        '
        Public Sub New(ByVal statistics__1 As Statistics)
            Me.BlackWins = statistics__1.BlackWins
            Me.WhiteWins = statistics__1.WhiteWins
            Me.OverallDraws = statistics__1.OverallDraws
            Me.BlackTotalScore = statistics__1.BlackTotalScore
            Me.WhiteTotalScore = statistics__1.WhiteTotalScore
            Me.ComputerWins = statistics__1.ComputerWins
            Me.UserWins = statistics__1.UserWins
            Me.VsComputerDraws = statistics__1.VsComputerDraws
            Me.ComputerTotalScore = statistics__1.ComputerTotalScore
            Me.UserTotalScore = statistics__1.UserTotalScore
        End Sub

        '
        ' Resets the game statistics.
        '
        Public Sub Reset()
            ' Set all counts to zero.
            Me.BlackWins = 0
            Me.WhiteWins = 0
            Me.OverallDraws = 0
            Me.BlackTotalScore = 0
            Me.WhiteTotalScore = 0
            Me.ComputerWins = 0
            Me.UserWins = 0
            Me.VsComputerDraws = 0
            Me.ComputerTotalScore = 0
            Me.UserTotalScore = 0
        End Sub

        '
        ' Updates the game statistics.
        '
        Public Sub Update(ByVal blackScore As Integer, ByVal whiteScore As Integer, ByVal computerColor As Integer, ByVal userColor As Integer)

            ' Update the overall Black vs. White counts.
            Me.BlackTotalScore += blackScore
            Me.WhiteTotalScore += whiteScore
            If blackScore > whiteScore Then
                Me.BlackWins += 1
            ElseIf whiteScore > blackScore Then
                Me.WhiteWins += 1
            Else
                Me.OverallDraws += 1
            End If

            ' Update the Computer vs. User counts, if applicable.
            If computerColor = Board.Empty OrElse userColor = Board.Empty Then
                Return
            End If

            ' Assign scores.
            Dim computerScore As Integer = blackScore
            Dim userScore As Integer = whiteScore
            If computerColor = Board.White Then
                computerScore = whiteScore
                userScore = blackScore
            End If
            ' Update the counts.
            Me.ComputerTotalScore += computerScore
            Me.UserTotalScore += userScore
            If computerScore > userScore Then
                Me.ComputerWins += 1
            ElseIf userScore > computerScore Then
                Me.UserWins += 1
            Else
                Me.VsComputerDraws += 1
            End If
        End Sub
    End Class
End Namespace
